package learningtests;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;

import org.junit.Ignore;
import org.junit.Test;

public class WritingTestFile {

    @Ignore @Test
    public void testSerializeCaseFile() {

        Map<String, String> cases = new HashMap<String, String>();

        String word = "abhorrence";

        String content = "@abhorrence /əb'hɔrəns/\n"
                + "*  danh từ\n - sự ghê tởm"
                + "=to have an abhorrence of+ sự ghét cay ghét đắng\n"
                + "=to hold in abhorrence of+ ghê tởm; ghét cay ghét đắng\n"
                + "- điều ghê tởm; cái bị ghét cay ghét đắng";

        cases.put(word, content);
        
        System.out.println(content.length());

        try {
            ObjectOutputStream writer = new ObjectOutputStream(
                    new FileOutputStream("C:\\test\\caseFile.txt"));

            writer.writeObject(cases);
        } catch (FileNotFoundException fnf) {
            fnf.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

    }

    @Ignore @Test
    public void testDeserializeCaseFile() {
        try {
            ObjectInputStream reader = new ObjectInputStream(
                    new FileInputStream("C:\\test\\caseFile.txt"));

            Map<String, String> cases = (Map<String, String>) reader
                    .readObject();
            
            assertNotNull(cases);
            String result = cases.get("abhorrence");
            System.out.println(result);
            assertEquals(193, result.length());
        } catch (FileNotFoundException fnf) {
            fnf.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        
    }
    
    @Ignore @Test
    public void testFileToString() {
        File file = new File("C:/test/av.index");
        System.out.println(file);
    }
    
    @Ignore @Test
    public void testReaderToString() {
        File file = new File("C:/test/av.dict.dz");
        FileInputStream reader = null;
        try {
            reader = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        System.out.println(reader);
    }
    
    @Test
    public void testUsingJavaIoFile() {
        File file = new File("C:/test");
        
        System.out.println(file.getAbsolutePath());
        
        File newFile = new File(file.getAbsolutePath() + File.separator + "av.index");
        
        assertTrue(newFile.exists());
        
        System.out.println(newFile);
    }
    
}
